<template>
  <div class="ai-dialogue">
    <div class="header">
      <span>
        <img
          src="https://blog-chen.oss-cn-shanghai.aliyuncs.com/favicon.ico"
          alt=""
        />
        {{ title }}</span
      >
      <span style="cursor: pointer;margin-right: 5px;" @click="$store.dispatch('customHide')">x</span>
    </div>
    <!-- 对话内容区域 -->
    <div class="dialogue-content" ref="dialogueContent"  v-if="showTag">
      <div>
        <div class="frequently" @click="$message.success('敬请期待~')">常见问题</div>
        <div class="artificial" @click="showArtificial()">人工客服</div>
      </div>
    </div>
    <artificial  :room="roomId"  v-if="artificialShow" @callBack="callBack"></artificial>
  </div>
</template>
  
  <script>
import artificial from "../artificial/artificial.vue";
export default {
  name: "custome",
  components: { artificial },
  data() {
    return {
      title: "资源售后",
      userInput: "", // 用户输入的内容
      chatResponses: [],
      eventSource: null,
      userInputList: [],
      abortController: null,
      observer: null,
      iconLoing: false,
      showTag: true,
      artificialShow: false,
      roomId:""
    };
  },
  methods: {
    showArtificial() {
        if (this.$store.state.UserInfo.id == null || this.$store.state.UserInfo.username == '') {
          this.$message.warning('请先登录再提问~')
          return
        }
      this.showTag = false;
   
      this.title = "人工客服";
    //  发生请求判断用户是否存在房间
    this.$api.customerService.createRoom().then(res=>{
        console.log(res);
        if(res.code==200){
          this.roomId = res.data.roomId
          this.artificialShow = true;
        }
    })

    },
    callBack(){
        this.showTag = true;
        this.artificialShow = false;
        this.title = "资源售后";
    }
  },
};
</script>
  
  <style scoped lang="less">
.ai-dialogue {
  position: fixed;
  flex-direction: column;
  width: 450px;
  z-index: 1001;
  // height: 800px;
  box-sizing: border-box;
  // padding: 12px 24px 8px;
  align-items: flex-start;
  grid-gap: 12px;
  gap: 12px;
  right: 14px;
  bottom: 14px;
  top: calc(60px + 1.767rem);
  background-image: url(https://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/086a891665bdd751f339293cc0d75038.svg),
    url(https://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/bgc2.1e5526a.png),
    linear-gradient(173deg, #f4f9ff -24.94%, #edf1f9 103.15%);
  background-repeat: no-repeat;
  background-position: 100% 0;
  background-attachment: fixed;
  background-size: auto;
  border-radius: 4px;
  font-size: 12px;
  font-style: normal;
  font-weight: 400;
  line-height: 24px;
  letter-spacing: 0.039px;
  box-shadow: 0 32px 60px 0 rgba(81, 87, 103, 0.12);
  overflow: hidden;
  .header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;

    span {
      font-size: 15px;
      font-weight: 700;

      img {
        width: 20px;
        height: 20px;
        vertical-align: sub;
      }
    }
  }

  .dialogue-content {
    margin-bottom: 12px;
    position: relative;
    overflow: auto;
    height: 100vh;
    

    &::-webkit-scrollbar {
      // display: none;
      /* 对于基于WebKit的浏览器 */
    }
    .frequently {
      height: 30px;
      width: 220px;
      text-align: center;
      line-height: 30px;
      margin: 0 auto;
      position: absolute;
      top: 38%;
      left: 100px;
      color: white;
      background: rgb(102, 175, 239);
      &:hover {
        cursor: pointer;
      }
    }

    .artificial {
      height: 30px;
      width: 220px;
      text-align: center;
      line-height: 30px;
      margin: 0 auto;
      position: absolute;
      top: 45%;
      left: 100px;
      color: white;
      background: rgb(102, 175, 239);
      &:hover {
        cursor: pointer;
      }
    }

    .author {
      width: 100%;
      min-width: 20px;
      margin: 5px 0;
      background-color: rgb(35, 147, 252);
      border-top-right-radius: 5px;
      border-bottom-right-radius: 5px;
      border-bottom-left-radius: 5px;

      span {
        font-size: 15px;
        font-weight: 700;

        img {
          width: 22px;
          height: 22px;
          vertical-align: sub;
          border-radius: 50%;
        }
      }
    }

    .aiComment {
      margin: 10px 0;
      width: 100%;
      min-width: 20px;
      background-color: rgb(220, 234, 248);

      border-top-left-radius: 5px;
      border-bottom-right-radius: 5px;
      border-bottom-left-radius: 5px;

      .top {
        display: flex;
        border-bottom: 1px solid rgba(170, 199, 251, 0.5);
        margin: 5px 0 3px 0;

        span {
          font-size: 15px;
          font-weight: 700;

          img {
            width: 22px;
            height: 22px;
            vertical-align: sub;
            border-radius: 50%;
          }
        }
      }

      /deep/ pre {
        background: rgb(121, 125, 125) !important;
      }

      /* /deep/ p code {
            padding: 5px;
            color: red;
            background-color: #f0f0f0;
          } */
    }
  }

  .input-area {
    position: fixed;
    display: flex;
    align-items: center;
    width: 390px;
    bottom: 26px;

    input {
      flex: 1;
      border: 1px solid #ccc;
      border-radius: 6px;
      padding: 8px;
    }

    /deep/ .el-icon-position {
      position: absolute;
      right: -22px;
      font-size: 20px;
      cursor: pointer;
    }

    /deep/ .el-icon-video-play {
      position: absolute;
      right: -22px;
      font-size: 20px;
      cursor: pointer;
    }
  }

  .bubble {
    max-width: 80%;
    padding: 8px;
    margin-bottom: 8px;
    border-radius: 4px;
    background-color: #f4f9ff;

    &.user {
      background-color: #edf1f9;
      align-self: flex-end;
    }
  }
}
</style>